package server;

import java.io.Serializable;
import java.rmi.RemoteException;

import net.RemoteMethod;
import net.retrievers.Retriever;

public class RetrieverRemoteMethodExecutor implements RemoteMethod {
	@SuppressWarnings("unchecked")
	protected Retriever systemRetriever;

	@SuppressWarnings("unchecked")
	public RetrieverRemoteMethodExecutor(Retriever systemRetriever) {
		this.systemRetriever = systemRetriever;
	}

	@SuppressWarnings("unchecked")
	public Object operation(String operation, Object... params) throws RemoteException {
		if ("set".equals(operation)) {
			systemRetriever.set((String) params[0], (Serializable) params[1], (String) params[2]);
			return "ok";
		}
		if ("add".equals(operation)) {
			return systemRetriever.add((Serializable) params[0], (String) params[1]);
		}
		if ("delete".equals(operation)) {
			systemRetriever.delete((String) params[0], (String) params[1]);
			return "ok";
		}
		if ("get".equals(operation)) {
			return systemRetriever.get((String) params[0], (String) params[1]);
		}
		return "no_op";
	}

}
